//This program uses a free function to calculate the "tax" of an employee
// based on his/her annual salary
//Referncing system files
#include <iostream.h>
//The ouput is formatted thru these two Classes
#include "textlib.h"
#include "iomanip.h"
//Declaring the Tax Free Function, note that the ";" are replaced by "{ }"
// in the implementation to facilitate compilation.
int calculateTax (int salary);
//Program starts here
int main()
{
int lowest_limit, highest_limit, salaryInc;
cout<<" Enter the lowest limit of annual"
" income you wish to calculate : $";
cin>> lowest_limit;
cout<<" Enter the highest limit of annual"
" income you wish to calculate: $";
cin>> highest_limit;
cout<<" Enter the salary incremental"
" interval you wish to calculate : $";
cin>> salaryInc;
cout<<endl;
cout<<endl;
//Tabulating the output values
cout<<" Salary ($)"<<'\t'
<<" Tax Amount ($) "
<<'\t'
<<" % Salary taxed "
<<endl;
//Underlining the output values
cout<<" __________"<<'\t'
<<" _______________ "
<<'\t'
<<" ______________ "
<<endl;
cout<<endl;
// Entering the loop in where all the taxes for annual incomes
// are calculated starting with the lowest bound to the upper bound
// in such a away that
while (salaryInc<=highest_limit)
{
cout<<setw(10)<<salaryInc<<'\t'
<<'\t'<<calculateTax(salaryInc)
<<'\t'<<setreal(15,1)
<<(100*calculateTax(salaryInc)/double (salaryInc))
<<endl;
salaryInc+=lowest_limit;
}
cout<<endl;
return 0;
}
//The Free function implementation here:
// A free function takes a value, performs computation then return the output
// A free function is similar to a member fuction in its prototype ( returnType,
// functionName and argument list) and doesn't have "Object Name" preceding it!!!
int calculateTax (int salary)
{
int Tax;
if (salary<=10000)
Tax=0;
else if (salary>10000 && salary<=20000)
Tax=(0.2*salary)-2000;
else if (salary>20000 && salary<=40000)
Tax=(0.4*salary)-6000;
else if (salary>40000 && salary<=60000)
Tax=(0.6*salary)-14000;
else
// All the tax ranges are covered up to $60,000
// so other icomes would definitly fall in this category.
Tax=(0.8*salary)-26000;
return Tax;
}
//Run:
/*
Enter the lowest limit of annual income you wish to calculate : $5000
Enter the highest limit of annual income you wish to calculate: $100000
Enter the salary incremental interval you wish to calculate : $5000
Salary ($) Tax Amount ($) % Salary taxed
__________ _______________ ______________
5000 0 0.0
10000 0 0.0
15000 1000 6.7
20000 2000 10.0
25000 4000 16.0
30000 6000 20.0
35000 8000 22.9
40000 10000 25.0
45000 13000 28.9
50000 16000 32.0
55000 19000 34.5
60000 22000 36.7
65000 26000 40.0
70000 30000 42.9
75000 34000 45.3
80000 38000 47.5
85000 42000 49.4
90000 46000 51.1
95000 50000 52.6
100000 54000 54.0
Press any key to continue
*/
|